package com.four.service.impl;

import com.four.entity.Dept;
import com.four.entity.Section;
import com.four.mapper.SectionMapper;
import com.four.service.SectionService;
import com.four.vo.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;


import java.util.List;

/**
 * @Description:
 * @author:LiWei
 * @date:2022年10月14日10:20
 */
@Service
public class SectionServiceImpl implements SectionService {

    @Autowired
    private SectionMapper sectionMapper;
    @Override
    public Result selectAll() {
        List<Section> sections=sectionMapper.selectAll();
        return new Result(200,"查询所有科室",sections);
    }

    @Override
    public Result add(Section record) {
        int insert=sectionMapper.insert(record);
        return new Result(200,"添加科室",insert);
    }

    @Override
    public Result delete(int id) {
        int delete=sectionMapper.deleteByPrimaryKey(id);
        return new Result(200,"删除科室",delete);
    }

    @Override
    public Result update(Section record) {
        int update=sectionMapper.updateByPrimaryKey(record);
        return new Result(200,"修改科室",update);
    }

    @Override
    public Result getDetails(int id) {
        List<Section> sections = this.sectionMapper.getDetails(id);
        return new Result(200,"查询详情成功",sections);
    }

    @Override
    public Result updateStatus(Section sectionId) {
        if (sectionId.getSectionStatus()==1){
            sectionId.setSectionStatus(0);
        }else {
            sectionId.setSectionStatus(1);
        }
        int i = sectionMapper.updateStatus(sectionId);
        return new Result(200,"修改部门状态成功",i);
    }

}
